/*
  学习目标：购物车练习
*/

import React from 'react';

export default class App extends React.Component {
  state = {
    count: 0,
  };

  // 1. 定义add函数
  handleClick = (num) => {
    this.setState({ count: this.state.count + num });
  };

  render() {
    return (
      <div>
        <p>当前数值为：{this.state.count}</p>
        <hr />
        <button
          // 2. 绑定事件
          onClick={() => this.handleClick(1)}
        >
          +1
        </button>
        <span>{this.state.count}</span>
        <button onClick={() => this.handleClick(-1)}>-1</button>
      </div>
    );
  }
}
